def _lagrange_interp_helper(x, nodes, j: int, n: int):
    """ helper function interpolates on node[j]"""
    assert (0 <= j <= n)
    prod = 1.0
    for i in range(n + 1):
        if i == j:
            continue
        prod *= (x - nodes[i]) / (nodes[j] - nodes[i])
    return prod


def lagrange(x, n: int):
    s = 0.0
    nodes = []
    for i in range(n + 1):
        nodes.append(-1 + 2 * i / n)
    for i in range(n + 1):
        s = s + _lagrange_interp_helper(x, nodes, i, n) * f(nodes[i])
    return s


def f(x: float):
    return 1 / (1 + 25 * x ** 2)
